在软件开发过程中,常常用到汉字转换为拼音码的情况,以实现快速检索数据,这里提供一个sqlserver 函数,以供随时调用
create function [lc0019999].[uf_pym_zh]
( @str nvarchar(4000),@i_uplow int )
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
set @str=rtrim(ltrim(@str))
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY (case when unicode(@word) between 19968 and 19968 20901
then (
select top 1 PY
from
(
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
评论